//
//  NMZRRDGroup.m
//  HNJYB
//
//  Created by Mag1cPanda on 2017/3/24.
//  Copyright © 2017年 Mag1cPanda. All rights reserved.
//

#import "NMZRRDGroup.h"

@implementation NMZRRDGroup

- (instancetype)initWithFrame:(CGRect)frame groupId:(NSString *)groupId
{
    self = [super initWithFrame:frame];
    if (self)
    {
        CGFloat viewWidth = ScreenWidth - 20;
        
        ZRRDView *titleView = [[ZRRDView alloc] initWithFrame:CGRectMake(10, 10, viewWidth, 50)];
        titleView.titleLab.hidden = YES;
        titleView.contentField.hidden = YES;
        [self addSubview:titleView];
        
        _titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, viewWidth, 50)];
        _titleLab.textAlignment = NSTextAlignmentCenter;
        [titleView addSubview:_titleLab];
        
        _xmView = [[ZRRDView alloc] initWithFrame:CGRectMake(10, titleView.maxY + 10, viewWidth, 50)];
        _xmView.titleLab.text = @"姓名:";
        [self addSubview:_xmView];
        
        _lxdhView = [[ZRRDView alloc] initWithFrame:CGRectMake(10, _xmView.maxY + 10, viewWidth, 50)];
        _lxdhView.titleLab.text = @"联系电话:";
        [self addSubview:_lxdhView];
        
        _zrlxView = [[ZRRDView alloc] initWithFrame:CGRectMake(10, _lxdhView.maxY + 10, viewWidth, 60)];//去掉主次责
        _zrlxView.titleLab.text = @"责任类型:";
        _zrlxView.contentField.hidden = YES;
        
        [self addSubview:_zrlxView];
        
        CGFloat labWidth = (_zrlxView.width - 110) / 3 - 20;
        CGFloat btnWidth = 20;
        CGFloat btnHeight = 20;
        CGFloat btnY = 20;
        
        _radio1 = [[QRadioButton alloc] initWithDelegate:self groupId:groupId];
        _radio1.frame = CGRectMake(110, btnY, btnWidth, btnHeight);
        [_zrlxView addSubview:_radio1];
        UILabel *lab1 = [[UILabel alloc] initWithFrame:CGRectMake(_radio1.maxX, btnY, labWidth, btnHeight)];
        lab1.text = @"全责";
        lab1.font = HNFont(14);
        [_zrlxView addSubview:lab1];
        
        _radio2 = [[QRadioButton alloc] initWithDelegate:self groupId:groupId];
        _radio2.frame = CGRectMake(lab1.maxX, btnY, btnWidth, btnHeight);
        [_zrlxView addSubview:_radio2];
        UILabel *lab2 = [[UILabel alloc] initWithFrame:CGRectMake(_radio2.maxX, btnY, labWidth, btnHeight)];
        lab2.text = @"无责";
        lab2.font = HNFont(14);
        [_zrlxView addSubview:lab2];
        
        _radio3 = [[QRadioButton alloc] initWithDelegate:self groupId:groupId];
        _radio3.frame = CGRectMake(lab2.maxX, btnY, btnWidth, btnHeight);
        [_zrlxView addSubview:_radio3];
        UILabel *lab3 = [[UILabel alloc] initWithFrame:CGRectMake(_radio3.maxX, btnY, labWidth, btnHeight)];
        lab3.text = @"同责";
        lab3.font = HNFont(14);
        [_zrlxView addSubview:lab3];
        
        _wftkView = [[ZRRDView alloc] initWithFrame:CGRectMake(10, _zrlxView.maxY + 10, viewWidth, 140)];
        _wftkView.titleLab.text = @"违法条款:";
        _wftkView.contentField.hidden = YES;
        
        _wftkLab = [UILabel new];
        _wftkLab.frame = CGRectMake(_wftkView.contentField.x, 10, _wftkView.contentField.width, 120);
        _wftkLab.textColor = [UIColor lightGrayColor];
        _wftkLab.font = HNFont(12);
        _wftkLab.numberOfLines = 0;
        _wftkLab.text = @"请选择违法条款";
        [_wftkView addSubview:_wftkLab];
        [self addSubview:_wftkView];
        
        
    }
    return self;
}

- (void)setTitle:(NSString *)title
{
    _title = title;
    _titleLab.text = title;
}


#pragma mark - QRadioButtonDelegate
- (void)didSelectedRadioButton:(QRadioButton *)radio groupId:(NSString *)groupId
{
    if (radio == _radio1)
    {
        _selectedIndex = @"0";
        if (_block)
        {
            _block(0);
        }
    }
    
    else if (radio == _radio2)
    {
        _selectedIndex = @"1";
        if (_block)
        {
            _block(1);
        }
    }
    
    else if (radio == _radio3)
    {
        _selectedIndex = @"2";
        if (_block)
        {
            _block(2);
        }
    }
    
    
    NSLog(@"%@ selectIndex -> %@", self, _selectedIndex);
}

@end
